//
//  MyselfViewController.m
//  51易借
//
//  Created by 张睿 on 2017/8/21.
//  Copyright © 2017年 张睿. All rights reserved.
//

#import "MyselfViewController.h"
#import "BorrowRecodeController.h"
#import "FinishInfoViewController.h"
#import "BankManagerViewController.h"
#import "SettingViewController.h"
#import "NoticeViewController.h"
#import "HelpCenterViewController.h"
#import "HomePageModel.h"
#import "BankDetailViewController.h"
#import "MemberInfoModel.h"
#import "QQSevrivceViewController.h"
#import "AppDelegate.h"
#import "LoginViewController.h"
#import "OrangeNavController.h"
#import "UIWebViewController.h"


@interface MyselfViewController ()
@property (nonatomic,strong)UIView * moneyView;
@property (nonatomic,strong)HomePageModel * pageModel;
@property (nonatomic,strong)NSMutableArray * numbersViews;
@property (nonatomic, weak)UIView * topView;
@property (nonatomic, weak)UILabel * showLabel;

@property (nonatomic, weak)UILabel * borrowMoenyLabel;
@property (nonatomic, weak)UIView * bottomView;
@property (nonatomic, weak)UIView * landscapeLine;
@property (nonatomic, weak)UIView * leftLineView;
@property (nonatomic, weak)UIView * rightLineView;
@property (nonatomic, strong)UIButton * recordButton;
@property (nonatomic, strong)UIButton * finishInfoButton;
@property (nonatomic, strong)UIButton * bankCardButton;
@property (nonatomic, strong)UIButton * settingButton;
@property (nonatomic, strong)UIButton * noticeButton;
@property (nonatomic, strong)UIButton * hpleButton;
@property (nonatomic, strong)UILabel * recordLabel;
@property (nonatomic, strong)UILabel * finishInfoLabel;
@property (nonatomic, strong)UILabel * bankCardLabel;
@property (nonatomic, strong)UILabel * settingLabel;
@property (nonatomic, strong)UILabel * noticeLabel;
@property (nonatomic, strong)UILabel * hpleLabel;

//@property (nonatomic, weak)UIScrollView * scrollView;
//@property (nonatomic, strong)UIView * BView;

@property (nonatomic, strong)UIButton * oneButton;
@property (nonatomic, strong)UIButton * twoButton;
@property (nonatomic, strong)UIButton * threeButton;
@property (nonatomic, strong)UIButton * fourButton;
@property (nonatomic, strong)UIButton * fiveButton;
@property (nonatomic, strong)UIButton * sixButton;

@end

@implementation MyselfViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = ColorWithRGB(0xf6f6f6);
    self.navigationItem.title = [self securityNumber:DEF_GET_OBJECT(myAccount)];
    
    [self setupNavBar];
    [self setupUI];
    [self loadData];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    if([DEF_GET_OBJECT(userToken) length]){
        
        [self loadState];
        [self loadAbleAccount];
    }else{
        
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        
        LoginViewController * loginVC = [LoginViewController new];
        
        loginVC.typeString = @"1";
        
        OrangeNavController * navVC = [[OrangeNavController alloc] initWithRootViewController:loginVC];
        
        appDelegate.window.rootViewController = navVC;
    }
}



-(NSString*)securityNumber:(NSString *)number
{
    if(number.length==11)
    {
        number = [number stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
    }
    return number;
}

- (void)setupNavBar{
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(0 * SCREENH6, 0 * SCREENH6, 23 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"客服"] forState:UIControlStateNormal];
    
    [backButton addTarget:self action:@selector(pushToServiceVC) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.rightBarButtonItem = leftButton;
    
    self.navigationController.navigationBar.translucent=YES;
    UIColor *color=[UIColor clearColor];
    CGRect rect =CGRectMake(0,0,self.view.frame.size.width,64 * SCREENH6);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context =UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:(UIBarMetricsDefault)];
    
    self.navigationController.navigationBar.clipsToBounds=YES;
}

-(void)setUpMoneyView:(NSInteger)money
{
    [self.moneyView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeFromSuperview];
    }];
    [self.numbersViews removeAllObjects];
    
    NSArray * numbers = [self nsinterLength:money];

    for(NSString * number in numbers)
    {
        UIButton * button = [self setupButton:number];
        [self.moneyView addSubview:button];
        [self.numbersViews addObject:button];
    }
    
}

- (NSArray*)nsinterLength:(NSInteger)x{
    if(x<=0)
        return @[@"0"];
    NSMutableArray * numbers = [NSMutableArray array];
    NSInteger sum=0,j=1;
    while( x >= 1 ) {
//        NSLog(@"%zd位数是 : %zd\n",j,x%10);
        [numbers insertObject: [NSString stringWithFormat:@"%zd",x%10]atIndex:0];
        x=x/10;
        sum++;
        j=j*10;
    }
    
    return numbers;
}


- (void)setupUI{
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
//    UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
//    
//    scrollView.backgroundColor = BACK_COLOR;
//    //    水平方向
//    scrollView.showsHorizontalScrollIndicator = NO;
//    //    垂直方向
//    scrollView.showsVerticalScrollIndicator = NO;
//    //    不管有没有设置contentSize,总是有弹簧效果(下拉刷新)
//    scrollView.alwaysBounceHorizontal = NO;
//    scrollView.alwaysBounceVertical = YES;
//    //    是否有弹簧效果
//    scrollView.bounces = YES;
//    //    scrollView.contentSize = self.view.bounds.size;
//    
//    self.scrollView = scrollView;
//    
//    [self.view addSubview:self.scrollView];
//    
//    
//    self.BView = [[UIView alloc] initWithFrame:self.view.bounds];
//    
//    self.BView.backgroundColor = [UIColor whiteColor];
//    self.BView.userInteractionEnabled = YES;
//    
//    [self.scrollView addSubview:self.BView];
    
    UIView * topView = [UIView new];
    
    topView.backgroundColor = ColorWithRGB(0xff7907);
    
    self.topView = topView;
    
    [self.view addSubview:self.topView];
    
    
    UILabel * showLabel = [UILabel new];
    
    showLabel.text = @"信用额度(元)";
    showLabel.textColor = [UIColor whiteColor];
    showLabel.font = [UIFont systemFontOfSize:12 * SCREENH6];
    showLabel.textAlignment = NSTextAlignmentCenter;
    
    self.showLabel = showLabel;
    
    [self.topView addSubview:self.showLabel];
    
    self.moneyView = [UIView new];
    
    [self.topView addSubview:self.moneyView];
    
    
    [self setUpMoneyView:0];
    
    
    UILabel * borrowMoenyLabel = [UILabel new];
    
    borrowMoenyLabel.text = @"可借额度  0";
    borrowMoenyLabel.textColor = [UIColor whiteColor];
    borrowMoenyLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:11.5 * SCREENH6];
    borrowMoenyLabel.textAlignment = NSTextAlignmentCenter;
    borrowMoenyLabel.backgroundColor = ColorWithRGB(0xfe8218);
    borrowMoenyLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
    borrowMoenyLabel.layer.borderWidth = 0.5 * SCREENH6;
    //处理圆角
    borrowMoenyLabel.layer.cornerRadius = 8.0f * SCREENH6;
    
    self.borrowMoenyLabel = borrowMoenyLabel;
    
    [self.view addSubview:self.borrowMoenyLabel];
    
    
    UIView * bottomView = [UIView new];
    
    bottomView.backgroundColor = [UIColor whiteColor];
    bottomView.userInteractionEnabled = YES;
    
    self.bottomView = bottomView;
    
    [self.view addSubview:self.bottomView];
    
    UIView * landscapeLine = [UIView new];
    
    landscapeLine.backgroundColor = ColorWithRGB(0xf6f6f6);
    
    self.landscapeLine = landscapeLine;
    
    [self.view addSubview:self.landscapeLine];
    
    UIView * leftLineView = [UIView new];
    
    leftLineView.backgroundColor = ColorWithRGB(0xf6f6f6);
    
    self.leftLineView = leftLineView;
    
    [self.view addSubview:self.leftLineView];
    
    UIView * rightLineView = [UIView new];
    
    rightLineView.backgroundColor = ColorWithRGB(0xf6f6f6);
    
    self.rightLineView = rightLineView;
    
    [self.view addSubview:self.rightLineView];
    
    
    self.recordButton = [self setupButtomButton:@"借款记录"];
    
    [self.view addSubview:self.recordButton];
    
    self.finishInfoButton = [self setupButtomButton:@"完善资料"];
    
    [self.view addSubview:self.finishInfoButton];
    
    self.bankCardButton = [self setupButtomButton:@"银行卡管理-拷贝"];
//    self.bankCardButton.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:self.bankCardButton];
    
    self.settingButton = [self setupButtomButton:@"设置"];
    
    [self.view addSubview:self.settingButton];
    
    self.noticeButton = [self setupButtomButton:@"平台公告"];
    
    [self.view addSubview:self.noticeButton];
    
    self.hpleButton = [self setupButtomButton:@"帮助中心"];
    
    [self.view addSubview:self.hpleButton];
    
    
    self.recordLabel = [self setupButtomLabel:@"借款记录"];
    
    [self.view addSubview:self.recordLabel];
    
    self.finishInfoLabel = [self setupButtomLabel:@"完善资料"];
    
    [self.view addSubview:self.finishInfoLabel];
    
    self.bankCardLabel = [self setupButtomLabel:@"银行卡管理"];
    
    
    [self.view addSubview:self.bankCardLabel];
    
    self.settingLabel = [self setupButtomLabel:@"设置"];
    
    [self.view addSubview:self.settingLabel];
    
    self.noticeLabel = [self setupButtomLabel:@"平台公告"];
    
    [self.view addSubview:self.noticeLabel];
    
    self.hpleLabel = [self setupButtomLabel:@"帮助中心"];
    
    [self.view addSubview:self.hpleLabel];
    

    self.oneButton = [self setBackButton];
    
    [self.view addSubview:self.oneButton];
    
    self.twoButton = [self setBackButton];
    
    [self.view addSubview:self.twoButton];
    
    self.threeButton = [self setBackButton];
    
    [self.view addSubview:self.threeButton];
    
    self.fourButton = [self setBackButton];
    
    [self.view addSubview:self.fourButton];
    
    self.fiveButton = [self setBackButton];
    
    [self.view addSubview:self.fiveButton];
    
    self.sixButton = [self setBackButton];
    
    [self.view addSubview:self.sixButton];
}


- (UIButton *)setupButton:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
//    [button setBackgroundImage:[UIImage imageNamed:@"钱框"] forState:UIControlStateNormal];
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:37 * SCREENH6];
    [button setTitleColor:ColorWithRGB(0xffffff) forState:UIControlStateNormal];
    button.adjustsImageWhenHighlighted = NO;
    button.layer.borderColor = [[UIColor whiteColor] CGColor];
    button.layer.borderWidth = 1 * SCREENH6;
    //处理圆角
    button.layer.cornerRadius = 5.0f * SCREENH6;
    
    
    return button;
}

- (UILabel *)setupButtomLabel:(NSString *)name{
    
    UILabel * label = [UILabel new];
    
    label.text = name;
    label.textColor = ColorWithRGB(0x8a8f99);
    label.font = [UIFont systemFontOfSize:12 * SCREENH6];
    label.textAlignment = NSTextAlignmentCenter;
    
    return label;
}



- (UIButton *)setupButtomButton:(NSString *)name{
    
    UIButton * button = [UIButton new];
    
    [button setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
//    [button addTarget:self action:@selector(didButtomViewButton:) forControlEvents:UIControlEventTouchUpInside];
//    button.backgroundColor = [UIColor redColor];
    button.userInteractionEnabled = NO;
    
    return button;
}

- (UIButton *)setBackButton{
    
    UIButton * button = [UIButton new];

    [button addTarget:self action:@selector(didButtomViewButton:) forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor clearColor];
    
    return button;
    
}

- (void)viewDidLayoutSubviews{
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(265 * SCREENH6);
    }];
    
    [self.showLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view).offset(90 * SCREENH6);
//        make.width.mas_equalTo(90 * SCREENH6);
//        make.height.mas_equalTo(19 * SCREENH6);
    }];
    
    
    [self.moneyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).offset(140 * SCREENH6);
        make.leading.mas_equalTo(self.view);
        make.height.mas_equalTo(55 * SCREENH6);
        make.trailing.mas_equalTo(self.view);
    }];
    
    
    __block CGFloat totalWidth = (54*self.moneyView.subviews.count-14)*SCREENH6;
    [self.moneyView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
   
            
            make.top.mas_equalTo(self.view).offset(140 * SCREENH6);
            make.leading.mas_equalTo(self.view).offset((SCREEN_WIDTH-totalWidth)/2+idx*54 * SCREENH6);
            make.height.mas_equalTo(55 * SCREENH6);
            make.width.mas_equalTo(40 * SCREENH6);
        }];
        
    }];
    
    [self.borrowMoenyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(20 * SCREENH6);
        make.top.mas_equalTo(self.moneyView.mas_bottom).offset(40 * SCREENH6);
        make.width.mas_equalTo(120 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.view);
        make.top.mas_equalTo(self.topView.mas_bottom);
        make.height.mas_equalTo(230 * SCREENH6);
    }];
    
    [self.landscapeLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.bottomView);
        make.height.mas_equalTo(1 * SCREENH6);
        make.centerY.mas_equalTo(self.bottomView);
    }];
    
    [self.leftLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self.bottomView);
        make.width.mas_equalTo(1 * SCREENH6);
        make.leading.mas_equalTo(self.bottomView).offset(124 * SCREENH6);
    }];
    
    [self.rightLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.top.bottom.mas_equalTo(self.leftLineView);
        make.trailing.mas_equalTo(self.bottomView).offset(-124 * SCREENH6);
    }];
    
    [self.recordButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bottomView).offset(31 * SCREENH6);
        make.leading.mas_equalTo(self.bottomView).offset(50 * SCREENH6);
        make.width.mas_equalTo(25 * SCREENH6);
        make.height.mas_equalTo(30 * SCREENH6);
    }];
    
    [self.finishInfoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.height.mas_equalTo(self.recordButton);
        make.leading.mas_equalTo(self.leftLineView.mas_trailing).offset(50 * SCREENH6);
    }];
    
    [self.bankCardButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.recordButton);
        make.trailing.mas_equalTo(self.bottomView).offset(-43 * SCREENH6);
        make.height.mas_equalTo(23 * SCREENH6);
        make.width.mas_equalTo(32 * SCREENH6);
    }];
    
    [self.settingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.recordButton);
        make.top.mas_equalTo(self.landscapeLine.mas_bottom).offset(31 * SCREENH6);
        make.width.mas_equalTo(33 * SCREENH6);
        make.height.mas_equalTo(33.5 * SCREENH6);
    }];
    
    [self.noticeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.settingButton);
        make.centerX.mas_equalTo(self.finishInfoButton);
        make.width.mas_equalTo(27 * SCREENH6);
        make.height.mas_equalTo(32 * SCREENH6);
    }];
    
    [self.hpleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.noticeButton);
        make.centerX.mas_equalTo(self.bankCardButton);
        make.width.mas_equalTo(27 * SCREENH6);
        make.height.mas_equalTo(29 * SCREENH6);
    }];
    
    [self.recordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.recordButton);
        make.top.mas_equalTo(self.recordButton.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.finishInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.finishInfoButton);
        make.centerY.mas_equalTo(self.recordLabel);
    }];
    
    [self.bankCardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.bankCardButton);
        make.centerY.mas_equalTo(self.finishInfoLabel);
    }];
    
    [self.settingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.settingButton);
        make.top.mas_equalTo(self.settingButton.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.noticeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.noticeButton);
        make.centerY.mas_equalTo(self.settingLabel);
    }];
    
    [self.hpleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.hpleButton);
        make.centerY.mas_equalTo(self.noticeLabel);
    }];
    
    [self.oneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view);
        make.top.mas_equalTo(self.topView.mas_bottom);
        make.bottom.mas_equalTo(self.landscapeLine.mas_top);
        make.trailing.mas_equalTo(self.leftLineView.mas_leading);
    }];
    
    [self.twoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self.oneButton);
        make.leading.mas_equalTo(self.oneButton.mas_trailing);
        make.trailing.mas_equalTo(self.rightLineView.mas_leading);
    }];
    
    [self.threeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self.twoButton);
        make.leading.mas_equalTo(self.twoButton.mas_trailing);
        make.trailing.mas_equalTo(self.view);
    }];
    
    [self.fourButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.oneButton.mas_bottom);
        make.leading.trailing.height.mas_equalTo(self.oneButton);
    }];
    
    [self.fiveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.mas_equalTo(self.fourButton);
        make.leading.trailing.mas_equalTo(self.twoButton);
    }];
    
    [self.sixButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.mas_equalTo(self.fiveButton);
        make.leading.trailing.mas_equalTo(self.threeButton);
    }];
}



- (void)didButtomViewButton:(UIButton *)sender{
    
    self.hidesBottomBarWhenPushed = YES;
    
    if (sender == self.fourButton) {
        if([DEF_GET_OBJECT(userToken) length]){

        SettingViewController * settingVC = [SettingViewController new];
        
        [self.navigationController pushViewController:settingVC animated:YES];
        }else
        {
            [self showHint:@"请先登录"];
        }
    }else if (sender == self.threeButton){
        if([DEF_GET_OBJECT(userToken) length]){
//        [self getPageModel:^(BOOL hasCard) {
//            
//            if(hasCard){
//                HIDDEN_TAB;
//                BankDetailViewController * bankVC = [BankDetailViewController new];
//                
//                [self.navigationController pushViewController:bankVC animated:YES];
//                
//                SHOW_TAB;
//            }else{
////                BankManagerViewController * bankVC = [BankManagerViewController new];
////                
////                [self.navigationController pushViewController:bankVC animated:YES];
//                HIDDEN_TAB;
//                FinishInfoViewController * finishVC = [FinishInfoViewController new];
//                
//                [self.navigationController pushViewController:finishVC animated:YES];
//                
//                SHOW_TAB;
//            }
//
//
//        }];
            
            [[NetworkTool manager] POST:[Interfacefile getDataCompletePercent] Param:nil andWaitStr:@"" waitView:self.view success:^(id  _Nullable responseObject) {
                
                //        NSLog(@"==%@",responseObject);
                
                if([[responseObject objectForKey:@"code"] intValue]==0)
                {
                    NSDictionary * dict = responseObject[@"data"];
                    
                    if ([dict[@"bankCardStatus"] intValue] == 3) {
                        HIDDEN_TAB;
                        BankDetailViewController * bankVC = [BankDetailViewController new];
                        
                        [self.navigationController pushViewController:bankVC animated:YES];
                        
                        SHOW_TAB;
                    }else{
                        HIDDEN_TAB;
                        FinishInfoViewController * finishVC = [FinishInfoViewController new];
                        
                        [self.navigationController pushViewController:finishVC animated:YES];
                        
                        SHOW_TAB;
                    }
                    
                }else{
                    
                    [self showHint:[responseObject objectForKey:@"message"]];
                    
                    
                }
            } andFailure:^(NSError * _Nonnull error) {
                [self showHint:@"网络错误"];
            }];
            
            
        }else
        {
            [self showHint:@"请先登录"];
        }
        
    }else if (sender == self.oneButton){
        if([DEF_GET_OBJECT(userToken) length]){
        BorrowRecodeController * borrowVC = [BorrowRecodeController new];
        
        [self.navigationController pushViewController:borrowVC animated:YES];
        }else
        {
            [self showHint:@"请先登录"];
        }
    }else if (sender == self.fiveButton){
        if([DEF_GET_OBJECT(userToken) length]){

        NoticeViewController * noticeVC = [NoticeViewController new];
        
        [self.navigationController pushViewController:noticeVC animated:YES];
    }else
    {
        [self showHint:@"请先登录"];
    }
    }else if (sender == self.twoButton){
        if([DEF_GET_OBJECT(userToken) length]){

        FinishInfoViewController * finishVC = [FinishInfoViewController new];
        
        [self.navigationController pushViewController:finishVC animated:YES];
        }else
        {
            [self showHint:@"请先登录"];
        }
    }else{
        if([DEF_GET_OBJECT(userToken) length]){
            
            //        HelpCenterViewController * helpVC = [HelpCenterViewController new];
            //
            //        [self.navigationController pushViewController:helpVC animated:YES];
            
            UIWebViewController * webVC = [UIWebViewController new];
            
            webVC.count = @"2";
            
            [self.navigationController pushViewController:webVC animated:YES];
    }else
    {
        [self showHint:@"请先登录"];
    }
    }

    SHOW_TAB;
    
}



- (void)pushToServiceVC{
    
    NSString *url = @"mqqwpa://im/chat?chat_type=crm&uin=800186070&version=1&src_type=web&web_src=http:://wpa.b.qq.com";
    NSURL *qqURL = [NSURL URLWithString:url];
    BOOL hasInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]];
    
    if (!hasInstalled) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" 提示 " message:@" 请先安装 QQ" delegate:nil cancelButtonTitle:@" 确定 " otherButtonTitles:nil, nil];
        [alert show];
//        [[UIApplication sharedApplication] openURL:qqURL];
    } else {
        [[UIApplication sharedApplication] openURL:qqURL];
    }
    
    
    
//    QQSevrivceViewController * qqVC = [QQSevrivceViewController new];
//    
//    [self.navigationController pushViewController:qqVC animated:YES];
}



- (void)loadState{
    
    [[NetworkTool manager] POST:@"common/getDefaultCreditLimit.json" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        
//        NSLog(@"===%@",responseObject);
        
        NSString * code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
        
        if ([code isEqualToString:@"0"]) {
            
            self.pageModel = [[HomePageModel alloc] initWithDictionary:[responseObject objectForKey:@"data"] error:nil];
            [self setUpMoneyView:[self.pageModel.myLoanCredit integerValue]];
            __block CGFloat totalWidth = (54*self.moneyView.subviews.count-14)*SCREENH6;
            [self.moneyView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [obj mas_makeConstraints:^(MASConstraintMaker *make) {
                    
                    
                    make.top.mas_equalTo(self.view).offset(140 * SCREENH6);
                    make.leading.mas_equalTo(self.view).offset((SCREEN_WIDTH-totalWidth)/2+idx*54 * SCREENH6);
                    make.height.mas_equalTo(55 * SCREENH6);
                    make.width.mas_equalTo(40 * SCREENH6);
                }];
                
            }];
            

//            self.borrowMoenyLabel.text = [NSString stringWithFormat:@"可借额度  %.2f元",[self.pageModel.myLoanCredit floatValue]];
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"==%@",error);
        
    }];
    
}

- (void)loadAbleAccount{
    
    [[NetworkTool shareManager] POST:[Interfacefile loadCurrentPersonalInfo] Param:nil andWaitStr:@"" waitView:self.view success:^(id  _Nullable responseObject) {
        if([[responseObject objectForKey:@"code"]intValue]==0)
        {
            MemberInfoModel * model = [[MemberInfoModel alloc] initWithDictionary:[responseObject objectForKey:@"data"] error:nil];
            
//            NSLog(@"==%@",model.ableLoanAmount);
            
            self.borrowMoenyLabel.text = [NSString stringWithFormat:@"可借额度  %.2f元",[model.ableLoanAmount floatValue]];
        }else{
            
            [self showHint:[responseObject objectForKey:@"message"]];
            
            
        }
    } andFailure:^(NSError * _Nonnull error) {
        [self showHint:@"网络错误"];
    }];
    
}

-(void)getPageModel:(void(^)(BOOL hasCard))complete
{
    
//    ParaModel*para = [ParaModel new];
//    
//    
//    [[NetworkTool shareManager] POST:[Interfacefile loadCurrentPersonalInfo] Param:[para toDictionary] andWaitStr:@"" waitView:self.view success:^(id  _Nullable responseObject) {
//        if([[responseObject objectForKey:@"code"]intValue]==0)
//        {
//           MemberInfoModel * model = [[MemberInfoModel alloc] initWithDictionary:[responseObject objectForKey:@"data"] error:nil];
//            
//            NSLog(@"==%@",model.ableLoanAmount);
//            
//            self.borrowMoenyLabel.text = [NSString stringWithFormat:@"可借额度  %.2f元",[model.ableLoanAmount floatValue]];
//            
//            complete(model.bankCard.length>0);
//        }else{
//            
//            [self showHint:[responseObject objectForKey:@"message"]];
//            
//            
//        }
//    } andFailure:^(NSError * _Nonnull error) {
//        [self showHint:@"网络错误"];
//    }];
    
}


- (void)loadData{
    
    [[NetworkTool shareManager] POST:[Interfacefile loadCurrentPersonalInfo] Param:nil andWaitStr:@"" waitView:self.view success:^(id  _Nullable responseObject) {
        if([[responseObject objectForKey:@"code"]intValue]==0)
        {
            MemberInfoModel * model = [[MemberInfoModel alloc] initWithDictionary:[responseObject objectForKey:@"data"] error:nil];
            
            DEF_SET_OBJECT(model.name, @"name");

        }else{
            
            [self showHint:[responseObject objectForKey:@"message"]];
        }
    } andFailure:^(NSError * _Nonnull error) {
        [self showHint:@"网络错误"];
    }];
    
}


@end
